/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package entity;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author kaibiibrahim
 */
@Entity
@Table(name = "produit")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Produit.findAll", query = "SELECT p FROM Produit p"),
    @NamedQuery(name = "Produit.findById", query = "SELECT p FROM Produit p WHERE p.id = :id"),
    @NamedQuery(name = "Produit.findByLibelle", query = "SELECT p FROM Produit p WHERE p.libelle = :libelle"),
    @NamedQuery(name = "Produit.findByPrixAchat", query = "SELECT p FROM Produit p WHERE p.prixAchat = :prixAchat"),
    @NamedQuery(name = "Produit.findByPrixVendre", query = "SELECT p FROM Produit p WHERE p.prixVendre = :prixVendre"),
    @NamedQuery(name = "Produit.findByQteDisp", query = "SELECT p FROM Produit p WHERE p.qteDisp = :qteDisp")})
public class Produit implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Column(name = "libelle")
    private String libelle;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Column(name = "prix_achat")
    private Double prixAchat;
    @Column(name = "prix_vendre")
    private Double prixVendre;
    @Column(name = "qte_disp")
    private Integer qteDisp;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "produit")
    private Collection<LignCmd> lignCmdCollection;
    @OneToMany(mappedBy = "produitId")
    private Collection<HstqStock> hstqStockCollection;

    public Produit() {
    }

    public Produit(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        Integer oldId = this.id;
        this.id = id;
        changeSupport.firePropertyChange("id", oldId, id);
    }

    public String getLibelle() {
        return libelle;
    }

    public void setLibelle(String libelle) {
        String oldLibelle = this.libelle;
        this.libelle = libelle;
        changeSupport.firePropertyChange("libelle", oldLibelle, libelle);
    }

    public Double getPrixAchat() {
        return prixAchat;
    }

    public void setPrixAchat(Double prixAchat) {
        Double oldPrixAchat = this.prixAchat;
        this.prixAchat = prixAchat;
        changeSupport.firePropertyChange("prixAchat", oldPrixAchat, prixAchat);
    }

    public Double getPrixVendre() {
        return prixVendre;
    }

    public void setPrixVendre(Double prixVendre) {
        Double oldPrixVendre = this.prixVendre;
        this.prixVendre = prixVendre;
        changeSupport.firePropertyChange("prixVendre", oldPrixVendre, prixVendre);
    }

    public Integer getQteDisp() {
        return qteDisp;
    }

    public void setQteDisp(Integer qteDisp) {
        Integer oldQteDisp = this.qteDisp;
        this.qteDisp = qteDisp;
        changeSupport.firePropertyChange("qteDisp", oldQteDisp, qteDisp);
    }

    @XmlTransient
    public Collection<LignCmd> getLignCmdCollection() {
        return lignCmdCollection;
    }

    public void setLignCmdCollection(Collection<LignCmd> lignCmdCollection) {
        this.lignCmdCollection = lignCmdCollection;
    }

    @XmlTransient
    public Collection<HstqStock> getHstqStockCollection() {
        return hstqStockCollection;
    }

    public void setHstqStockCollection(Collection<HstqStock> hstqStockCollection) {
        this.hstqStockCollection = hstqStockCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Produit)) {
            return false;
        }
        Produit other = (Produit) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.Produit[ id=" + id + " ]";
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }
    
}
